<?php
    /**
    *
    */
    class Core_Model_Model extends Core_Bean
    {
        private $_ID;
        private $_Name;
        function __construct()
        {
            parent::__construct('model');
        }

        public function setName($name)
        {
            if (!empty($name)) {
                $this->_Name = $name;
                if (empty($this->_ID)) {
                    $id = $this->model->Name->$name->model__id;
                    if (!empty($id)) {
                        $this->_ID = $id;
                        return true;
                    }
                }
                return null;
            }
            return false;
        }

        public function saveID()
        {
            if (!empty($this->_ID)) {
                return true;
            }
            if (!empty($this->_Name)) {
                $bind = array();
                $bind['model__name'] = $this->_Name;
                $result = $this->insert($bind);
                if (!$result) {
                    $this->setError('保存分类数据失败！');
                }
                $this->_ID = $this->db->lastInsertId(DB_TABLE_PREFIX . 'model');
                return true;
            } else {
                $this->setError('缺少分类名称！');
            }
            return false;
        }

        public function getID()
        {
            return $this->_ID;
        }

        public function insert($bind)
        {
            return $this->db->insert($this->tableName, $bind);
        }

    }